const express = require('express');
const { formatResponse } = require('../utils/tool');
const { addBlogTypeService, getBlogTypeByIdService, updateBlogTypeService, getBlogTypeListService, delBlogTypeService } = require('../service/blogTypeService');
const router = express.Router();


// 新增博客分类
router.post('/', async function (req, res, next) {
  let result = await addBlogTypeService(req.body)
  res.send(formatResponse(0, "新增成功", result))
});

// 获取博客分类列表
router.get('/', async function (req, res, next) {
  let blogTypeList = await getBlogTypeListService()
  res.send(formatResponse(0, "获取成功", blogTypeList))
});

// 获取一个博客分类
router.get('/:id', async function (req, res, next) {
  let id = req.params.id
  let blogType = await getBlogTypeByIdService(id)
  res.send(formatResponse(0, "获取成功", blogType))
});

// 删除博客分类
router.delete('/:id', async function (req, res, next) {
  let id = req.params.id
  await delBlogTypeService(id)
  res.send(formatResponse(0, "删除成功"))
});

// 修改博客分类
router.put('/:id', async function (req, res, next) {
  let id = req.params.id
  let result = await updateBlogTypeService(id, req.body)
  res.send(formatResponse(0, "修改成功", result))

});

module.exports = router;